package md.lanjing.com.module_home.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.ToastUtils;


import md.lanjing.com.module_home.api.HomeApiService;
import md.lanjing.com.module_home.bean.ForgetLoginPwdRequest;
import md.lanjing.com.module_home.bean.ForgetLoginPwdResponse;
import md.lanjing.com.module_home.bean.ForgetPwdResponse;
import md.lanjing.com.module_home.bean.RegisterSecurityCodeRequest;
import retrofit2.Call;
import retrofit2.Response;

public class ForgetLoginPwdContact {
    public static class ForgetLoginPwdPresent extends BasePresent<IForgetLoginPwdView> {

        public void forgetLoginPwd(final Context context, String code, String logPwd,String tel){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            ForgetLoginPwdRequest request=new ForgetLoginPwdRequest(tel, Md5Utils.stringToMD5(logPwd),code);
            service.forgetLoginPwd(request).enqueue(new NetCallBack<ForgetLoginPwdResponse>() {
                @Override
                public void onSuccess(Call<ForgetLoginPwdResponse> call, Response<ForgetLoginPwdResponse> response) {
                    if (getView()!=null){
                        getView().getForgetLoginPwdData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");

                }
            });

        }

        public void getForgetPwdSecurityCode(final Context context, String tel){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            RegisterSecurityCodeRequest request=new RegisterSecurityCodeRequest(tel,2);
            service.getForgetPwdSecurityCode(request).enqueue(new NetCallBack<ForgetPwdResponse>() {
                @Override
                public void onSuccess(Call<ForgetPwdResponse> call, Response<ForgetPwdResponse> response) {
                    if (getView()!=null){
                        getView().getSecurityCode(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }
    }

    public interface IForgetLoginPwdView extends IBaseView {
       void getForgetLoginPwdData(Response<ForgetLoginPwdResponse> response);
       void getSecurityCode(Response<ForgetPwdResponse> response);
    }
}
